
#include <stdio.h>
#include <string.h>

#define PRINT_ERR(msg) do{ \
        perror(msg);\
        return -1;\
    }while(0)
int main(int argc, const char *argv[])
{
    FILE *fp;
    int img_size;
    unsigned char color[3] = {0xff, //蓝
                              0xff,//绿
                              0xff};  //红
    if (argc != 2)
    {
        fprintf(stderr, "input error,try again\n");
        fprintf(stderr, "usage:./a.out picture.bmp\n");
        return -1;
    }
    if ((fp = fopen(argv[1], "r+")) == NULL)
        PRINT_ERR("fopen error");

    fseek(fp, 2, SEEK_SET);
    fread(&img_size, 4, 1, fp);

    printf("img_size = %d\n", img_size);

    fseek(fp, 54000, SEEK_SET); //跳过图片的头

    for (int j = 0; j < 500; j++) //写多少行
    {
        for (int i = 0; i < 10; i++) //每一行内的像素点
        {
            fwrite(color, 3, 1, fp); //每一个点占3个字节
        }
    }

    fclose(fp);

    return 0;
}